/**
 * Created by grasp on 2017/6/27.
 */
'use strict';
import IdentifyBean from './IdentifyBean';
require('../../lib.xjs/util/DateUtil');

export default class Person {

    static QUERYING         :number = 0;
    static RETURN_SUCCESS   :number = 1;
    static RETURN_FAIL      :number = 2;

    mStatus = Person.QUERYING;

    mSendTime   : string;         // 查询开始时间
    mReceiveTime: string;      // 查询结束时间
    mCreditId   : string;         // 身份证号码

    mIdentify       = new Set();        // 比对身份信息
    mPersonParmas   = [];               // 一般身份信息
    mWfjls          = new Set();        // 违法犯罪

    /** 获取默认note（初始） */
    static getNote(id) {
        let mNote = new Person();
        mNote.mCreditId = id;
        mNote.mSendTime = new Date().Format("hh:mm:ss");
        mNote.mStatus = Person.QUERYING;
        return mNote;
    }

    /** 用加载成功数据包装Bean */
    static formatSuccess(person, personJson) {
        if(typeof person === 'undefined' || typeof personJson === 'undefined') return;
        person.mReceiveTime     = new Date().Format("hh:mm:ss");
        person.mStatus          = Person.RETURN_SUCCESS;
        person.mIdentify        = personJson.compareresult;
        person.mPersonParmas    = [...person.mPersonParmas, ...personJson.result];
        // person.mWfjls        = personJson.compareresult;

    }

    /** 用加载失败数据包装Bean */
    static formatFail(person) {
        if(typeof person === 'undefined') return;
        person.mReceiveTime = new Date().Format("hh:mm:ss");
        person.mStatus = Person.RETURN_FAIL;
    }

    /** --- */
    getmIdentify() {
        if (this.mIdentify !== null && this.mIdentify.size() === 1 && this.mIdentify.get(0).n.contains("1")) {
            this.mIdentify.get(0).l = "正常";
        }
        else if (this.mIdentify !== null && this.mIdentify.size() > 1) {
            let target = null;
            for (let temp of this.mIdentify) {
                if (temp.l.contains("全国常口")) {
                    target = temp;
                    break;
                }
            }
            this.mIdentify.remove(target);
        }
        else if (this.mIdentify !== null && this.mIdentify.size() === 0) {
            this.mIdentify = new Set();
            let iden = new IdentifyBean();
            iden.l = "正常";
            iden.a = "#000000";
            iden.c = "#000000";
            iden.n = "1";
            iden.v = "正常";
            this.mIdentify.add(iden);
        }
        return this.mIdentify;
    }

    static getName() {
        for (let param of this.mPersonParmas) {
            if (param.n === ("XM")) return param.v;
        }
        return "";
    }

}
